package com.zhao.data.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@MappedSuperclass
public abstract class BaseEntity implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	private String id;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "createtime")
	private Date createTime;

	@Column(name = "createuser")
	private Long createUser;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "modifytime")
	private Date modifyTime;

	@Column(name = "modifyuser")
	private Long modifyUser;

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getModifyTime() {
		return this.modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	@PrePersist
	void onCreateUser() {
		this.setCreateTime(new Date());
		this.setModifyTime(new Date());
	}

	@PreUpdate
	void onModifyUser() {
		this.setModifyTime(new Timestamp((new Date()).getTime()));
	}
}
